package top.xzxsrq.datahelp.zhixin.config;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import top.xzxsrq.common.utils.MyFileUtils;
import top.xzxsrq.datahelp.zhixin.ZhixinApplication;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;

/**
 * @program: datahelp
 * @create: 2021-11-09 17:46
 **/
@Component
@Getter
@Slf4j
public class FileConfig {
    @Value("${app.fileBasePath}")
    private String fileBasePath;

    public static final String RELATION_FILE_PRE = "__zhixin_relationship_";

    public static final String SUFFIX = "json";

    @PostConstruct
    public void beanInit() throws IOException { // 构造方法 -> @Autowired(Value) -> @PostConstruct
        if ("appPath".equals(this.fileBasePath)) {
            this.fileBasePath = MyFileUtils.getAppPath(ZhixinApplication.class);
        } else if ("projectPath".equals(this.fileBasePath)) {
            this.fileBasePath = MyFileUtils.getProjectPath();
        }
        this.fileBasePath = this.fileBasePath + File.separator + "zhixinTableDir";
    }
}
